<template>
  <div>
    <van-notice-bar
        left-icon="volume-o"
        text="请遵守相关法律法规，上传真实信息！"
    />
    <van-image
        width="100%"
        height="150"
        :src="image"
        fit="fill"
    />
    <div style="margin-top: 15%">
      <div style="margin: 15%">
        <van-button color="linear-gradient(to right, #ff6034, #ee0a24)" block @click="routerHelper('uploadAntigenMsg')">
          新冠抗原检测（个人办理）
        </van-button>
      </div>
      <div style="margin: 15%">
        <van-button color="linear-gradient(to right, #43CBFF, #9708CC)" block @click="routerHelper('uploadAntigenMsgForFmly')">
          新冠抗原检测(为家人代办)
          </van-button>
      </div>
      <div style="margin: 15%">
        <van-button color="linear-gradient(to right, #CE9FFC, #7367F0)" block @click="ifDetectionDataHave()">
          结果查询
        </van-button>
      </div>
    </div>
  </div>
</template>

<script>
import image from "@/assets/抗原检测.png";
import {Toast} from 'vant';
export default {
  name: 'AntigenHome',
  data() {
    return {
      image: image,
      identity: ''
    }
  },
  mounted() {
    this.getUserIdentity();
  },
  methods: {

    getUserIdentity(){
      var userInfo = JSON.parse(localStorage.getItem("userInfo"));
      this.identity = userInfo.identity;
    },

    routerHelper(arg) {
      this.$router.push('/' + arg)
    },

    ifDetectionDataHave(){
      this.$axios(
          {
            method: "post",
            url: "http://localhost:8085/detection/ifDetectionDataHave",
            data: {
              identity: this.identity
            }
          }
      ).then(res => {
        if (res.data.code === 200) {
          let judge = res.data.data;
          if (judge > 0){
            this.routerHelper('antigenResult');
          }
          else{
            Toast({
              message:'您暂时没有任何抗原检测数据',
              duration:3000
            });
          }
        }
      })
    }
  }
}
</script>


